package com.liyuhan.onlinetaxibackground.Service.impl;

import com.liyuhan.onlinetaxibackground.POJO.Comment;
import com.liyuhan.onlinetaxibackground.POJO.CompletedOrder;
import com.liyuhan.onlinetaxibackground.POJO.Passenger;
import com.liyuhan.onlinetaxibackground.POJO.User;
import com.liyuhan.onlinetaxibackground.Repository.CommentRepository;
import com.liyuhan.onlinetaxibackground.Repository.CompletedOrderRepository;
import com.liyuhan.onlinetaxibackground.Repository.PassengerRepository;
import com.liyuhan.onlinetaxibackground.Repository.UserRepository;
import com.liyuhan.onlinetaxibackground.Service.PassengerService;
import com.liyuhan.onlinetaxibackground.Util.GetRequestBody;
import com.liyuhan.onlinetaxibackground.Util.JedisPoolUtils;
import com.liyuhan.onlinetaxibackground.Util.TimeUtil;
import com.liyuhan.onlinetaxibackground.dto.DataRequest;
import com.liyuhan.onlinetaxibackground.dto.DataResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PassengerImpl implements PassengerService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private PassengerRepository passengerRepository;
    @Autowired
    private CompletedOrderRepository completedOrderRepository;
    @Autowired
    private CommentRepository commentRepository;

    // 响应参数
    private Map<String, String> map = new HashMap<>();

    @Override
    public void saveCity(String request) {
        DataRequest requestBody = GetRequestBody.getRequestBody(request);

        String phone = requestBody.get("phone").toString();
        String city = requestBody.get("city").toString();

        if (userRepository.findUserByPhone(phone).isPresent()) {
            User user = userRepository.findUserByPhone(phone).get();
            if (passengerRepository.findPassengerByUser(user).isPresent()) {
                Passenger passenger = passengerRepository.findPassengerByUser(user).get();
                passenger.setCity(city);

                passengerRepository.save(passenger);
            }
        }
    }
}
